package org.cedar.syntaxcore;

import java.util.Vector;
import java.util.Collection;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description: 队列封装
 * </p>
 * <p>
 * Copyright: Copyright (c) 2005
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author net.wzh
 * @version 1.0
 */

public class Queue extends Vector {
	private static final long serialVersionUID = -780074745995637101L;

	private int currPos = 0;
	public Queue() {
	}

	public Queue resetPos(){
		this.currPos = 0;
		return this;
	}
	
	public boolean isEmpty(){
		return this.currPos >= this.size() ;
	}
	public Queue(int p0, int p1) {
		super(p0, p1);
	}

	public Queue(int p0) {
		super(p0);
	}

	public Queue(Collection p0) {
		super(p0);
	}

	public synchronized void enQueue(Object x) {
		super.addElement(x);
	}

	/* 队列若为空，引发EmptyQueueException异常 */
	public synchronized Object deQueue() {
		if (currPos < this.size()) {
			Object x = super.elementAt(currPos);
//			super.removeElementAt(0);
			currPos++;
			return x;
		}
		return null;
	}

	public synchronized Object front() {
		if (this.empty())
			return null;
		return super.elementAt(0);
	}

	public boolean empty() {
		return super.isEmpty();
	}

	public synchronized void clear() {
		super.removeAllElements();
	}

	public int search(Object x) {
		return super.indexOf(x);
	}
}
